<?php

namespace App\Listeners;

use App\Events\UserRegistered;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use QrCode;
use App\Models\User;

class CreateUserQrcode
{
    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     *
     * @param  UserRegistered  $event
     * @return void
     */
    public function handle(UserRegistered $event)
    {
        $user_id = $event->user_id;
        $user = User::find($user_id);
        QrCode::size(250)
            ->format('png')
            ->errorCorrection('H')
            ->generate(url('/register/' . $user->register_code), public_path('qrcode/' . $user->register_code . '.png'));
        $user->invite_img = 'qrcode/'. $user->register_code .'.png';
        $user->save();
    }
}
